package com.example.demo.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.domain.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.ShardingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Date 2023/10/26 11:02
 */
@Service
public class ShardingServiceImpl extends ServiceImpl<UserMapper, User> implements ShardingService {

    @Autowired
    UserMapper mapper;



    @Override
    public void insert(long id) {
/*        Integer id = mapper.();
        if(id==null){
            id = 1;
        }*/
/*        List<User> users = new ArrayList<>();
        for (int i = id+1; i <id+1+100; i++) {
            users.add(User.builder().age(18).name("慈" + i).build());
        }*/
        User user = User.builder().name("慈" + id).age(18).build();
        System.out.println(user);
        mapper.insert(user);

    }


    @Override
    public void inserts() {

        Random rand = new Random();
        int randomNumber = rand.nextInt(1000);
        long num = Long.valueOf(randomNumber);

        List<User> users = new ArrayList<>();
        for (int i = 0; i <10; i++) {
            User build = User.builder().id(num + i).age(18).name("慈" + i).build();
            users.add(build);

        }
        try {

            mapper.inserts2(users);
        } catch (Exception e) {
            e.printStackTrace();
        }

/*        QueryWrapper<User> wrapper = new QueryWrapper<>();
        mapper.sa();*/

    }
}
